<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>双向绑定</title>
</head>
<body>
  <input type="text" id="input">
  <p id="text"></p>

  <script>
    var input = document.getElementById('input')
    var text = document.getElementById('text')
    var obj = {}

    Object.defineProperty(obj, 'msg', {
      set: function(newValue) {
        input.value = newValue
        text.innerHTML = newValue
      }
    })

    input.addEventListener('keyup', function(e) {
      obj.msg = e.target.value
    })
  
  </script>
</body>
</html>